export function _throttle (fn, interval, event) {
  let last
  let timer
  interval = interval || 200
  return function (event) {
    let th = this
    let args = arguments
    let now = +new Date()
    if (last && now - last < interval) {
      clearTimeout(timer)
      timer = setTimeout(function () {
        last = now
        fn.apply(th, args)
      }, interval)
    } else {
      last = now
      fn.apply(th, args)
    }
  }
}

// 获取日期
export function getDate (type) {
  let obj = {}
  let date = new Date()
  let Y = date.getFullYear()
  let M = date.getMonth() + 1
  let D = date.getDate()
  let H = date.getHours()
  let m = date.getMinutes()
  let week = '星期一'
  switch (date.getDay()) {
    case 1: week = '星期一'
      break
    case 2: week = '星期二'
      break
    case 3: week = '星期三'
      break
    case 4: week = '星期四'
      break
    case 5: week = '星期五'
      break
    case 6: week = '星期六'
      break
    case 7: week = '星期天'
      break
  }
  if (M < 10) {
    M = '0' + M
  }
  if (D < 10) {
    D = '0' + D
  }
  if (H < 10) {
    H = '0' + H
  }
  if (m < 10) {
    m = '0' + m
  }
  if (H >= 12) {
    obj.ackemma = 'PM'
  } else {
    obj.ackemma = 'AM'
  }
  switch (type) {
    case 'yyyy-mm-dd': obj.days = Y + '-' + M + '-' + D
      break
    case 'yyyy-mm-dd hh:mm': obj.days = Y + '-' + M + '-' + D + ' ' + H + ':' + m
      break
    case 'yyyy.mm.dd': obj.days = Y + '.' + M + '.' + D
      break
    case 'yyyy.mm.dd hh:mm': obj.days = Y + '.' + M + '.' + D + ' ' + H + ':' + m
      break
    case 'yyyy/mm/dd': obj.days = Y + '/' + M + '/' + D
      break
    case 'yyyy/mm/dd hh:mm': obj.days = Y + '/' + M + '/' + D + ' ' + H + ':' + m
      break
  }
  obj.years = Y
  obj.month = M
  obj.date = D
  obj.hours = H
  obj.minute = m
  obj.week = week
  return obj
}
